package com.gaogzhen.designPattern.immutableObject.immutable;

import java.sql.Connection;
import java.util.concurrent.TimeUnit;

/**
 * 测试连接池
 */
public class PoolTest {
    public static void main(String[] args) {
        Pool p = new Pool(2);
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                Connection connection = p.getConnection();
                try {
                    // 模拟连接使用耗时
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    p.close(connection);
                }

            }).start();
        }
    }
}
